package acwing._1_1AlgorithmBasic;

/**
 * @Project : ProgrammingExercises
 * @Package : ACWing.Learning.AlgorithmTemplate
 * @File : _1_6BitOperator.java
 * @Author : WangRuoyu
 * @Date 2023/3/11 10:30
 */

public class _1_6BitOperator {
    // 位运算
    static void numKbit(int x, int k) {
        for (int i = k; i >= 0; --i) {
            System.out.print(x >> i & 1);
        }
    }

    static int lowBit(int q) {
        return q & -q;
//        return q & (~q + 1);
    }

    static void number1counts(int q[]) {
        for (int i = 0; i < q.length; ++i) {
            int x = q[i];
            int count = 0;

            while (lowBit(x) != 0) {
                count++;
                x = x - lowBit(x);
            }

            System.out.println(count);
        }
    }
}

